package com.azhoucode.config;

import com.azhoucode.common.SimpleResponse;

import com.azhoucode.enums.BaseErrorEnum;
import org.hibernate.validator.internal.engine.path.PathImpl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.validation.BindException;
import org.springframework.validation.FieldError;
import org.springframework.web.HttpRequestMethodNotSupportedException;
import org.springframework.web.bind.MissingServletRequestParameterException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MaxUploadSizeExceededException;
import org.springframework.web.servlet.NoHandlerFoundException;

import javax.validation.ConstraintViolation;
import javax.validation.ConstraintViolationException;
import java.util.List;
import java.util.Set;

/**
 * 统一异常处理器
 */
@ControllerAdvice
@SuppressWarnings("all")
public class GlobalExceptionHandler {

    private final Logger logger = LoggerFactory.getLogger(getClass());

    /**
     * 处理{@link Exception}异常
     *
     * @return 返回统一json数据对象
     */
    @ExceptionHandler(Exception.class)
    @ResponseBody
    public SimpleResponse errorProceed(Exception e) {
        logger.error("请求发生错误。", e);
        return SimpleResponse.error(BaseErrorEnum.SERVER_ERROR);
    }

}
